$(document).ready(function() {
	var shead = $("#dataHeadTr th");
	// alert(shead.length);
	for ( var i = 0; i < shead.length; i++) {
		var objHead = $(shead[i]);
		var headId = objHead.attr("id");
		if (headId != "") {
		objHead.addClass("mousepointer");
		objHead.click(function() {
			var headId = $(this).attr("id");
				sortPage(headId);
		});
		}
		var sinspan = $("span", objHead);
		if (headId != "") {
			if (headId ==$("#orderField").val()) {
				var orderde=$("#orderDirection") .val();
				if (orderde=="ASC") {
					sinspan.addClass("iconPosition ui-icon ui-icon-triangle-1-n");
				} else {
					sinspan.addClass("iconPosition ui-icon ui-icon-triangle-1-s");
				}
			} else {
				sinspan.addClass("iconPosition ui-icon ui-icon-carat-2-n-s");
			}
		}
	}
});

function addNew(url)
{
	 $("#pageForm").attr("action",url);
	 $("#pageForm").submit();
}

function goPage(pageNo) {
	$("#pageNo").val(pageNo);
	$("#pageForm").submit();
}
 
function deleteResult(url,ids)
{
	if(confirm("确认删除？")){
	$.ajax({
		type: 'POST',
		url:url+"delete.do",
		data:"id="+ids,
		cache: false,
		success: function (data){
			alert("删除成功！");
			location.reload();
		}
	});
		}
}
function sortPage(orderProperty) {
	var defaultOrder = "ASC";
	if ($("#orderField").val() == orderProperty) {
		if ($("#orderDirection").val() == "") {
			$("#orderDirection").val(defaultOrder);
		} else if ($("#orderDirection").val() == "DESC") {
			$("#orderDirection").val("ASC");
		} else if ($("#orderDirection").val() == "ASC") {
			$("#orderDirection").val("DESC");
		}
	} else {
		$("#orderField").val(orderProperty);
		$("#orderDirection").val(defaultOrder);
	}
	$("#pageForm").submit();
}

function search() {
	$("#orderProperty").val("");
	$("#orderDirection").val("");
	$("#pageNo").val("1");
	$("#pageForm").submit();
}